package me.wangqu.weiyouqu.web.rest;

import com.codahale.metrics.annotation.Timed;
import me.wangqu.weiyouqu.security.SecurityUtils;
import me.wangqu.weiyouqu.web.rest.business.model.CashAccount;
import me.wangqu.weiyouqu.web.rest.business.service.CashAccountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * REST controller for managing WithdrawAccount.
 */
@RestController
@RequestMapping("/api")
public class CashAccountResource {

    private final Logger log = LoggerFactory.getLogger(CashAccountResource.class);

    @Autowired
    private CashAccountService cashAccountService;

    @RequestMapping(value = "/cash-accounts/self",
        method = RequestMethod.GET,
        produces = MediaType.APPLICATION_JSON_VALUE)
    @Timed
    public ResponseEntity<CashAccount> getSelfCashAccount() {
        log.debug("REST request to get self Journal");
        // 获取用户帐户信息
        CashAccount ca = cashAccountService.getSelfCashAccount(SecurityUtils.getCurrentUserLogin());
        return ca == null ? ResponseEntity.badRequest().body(null) : ResponseEntity.ok(ca);
    }

}
